<?php
	
	$path = $_GET['path'].'/';
	
	file_put_contents('../data/CurrentPath',$_GET['path']);
	$folders = array();
	$filelist = array();
	$res = array();	
	$files = glob($path."*" );
	foreach($files as $file){		
		$pathinfo = json_encode(pathinfo($file));
		$pathinfo = json_decode($pathinfo);		
		$pathinfo->fullname = $pathinfo->dirname.'/'.$pathinfo->basename;
		$pathinfo->ctime = filectime($file);
		$pathinfo->mtime = filemtime($file);
		$pathinfo->size = filesize($file);

		if(is_dir($file)){
			$pathinfo->type = 'folder' ;
			$pathinfo->img = "resource/images/file_icon/folder.png";
			array_push($folders,$pathinfo);
		}else{
			$pathinfo->type = 'file' ;
			$pathinfo->img = geticon($pathinfo);
			array_push($filelist,$pathinfo);
		}		 
	}
	$res = array_merge($folders,$filelist);
	
	function geticon($pathinfo){
		if(!property_exists($pathinfo,"extension")){
			return "resource/images/file_icon/file.png";
		}
		if(file_exists("../resource/images/file_icon/".$pathinfo->extension.".png")){
			return "resource/images/file_icon/".$pathinfo->extension.".png";
		}else{
			return "resource/images/file_icon/file.png";
		}
	}
	echo  (json_encode($res));
?>